import {debounce} from 'common/utils';
import BackTop from 'components/content/backTop/BackTop';

export const itemListenerMixin = {
  data() {
    return{
      itemImgListener: null,
    }
  },
  mounted() {
    // 防抖 //每一次加载图片就刷新获取高度
    let newRefresh = debounce(this.$refs.scroll.refresh,100)
    // 对监听事件进行保存：
    this.itemImgListener = () => {
      newRefresh()
    }
     // 监听item中图片加载完成
    this.$bus.$on('itemImageLoad', this.itemImgListener)
  }
}

export const backTopMixin = {
  components: {
    BackTop
  },
  data() {
    return {
      isShowBackTop: false
    }
  },
  methods: {
    backClick (){ //点击回到顶部
      this.$refs.scroll.scrollTo(0 , 0, 500)
    },
    listenShowBackTop(position){
      this.isShowBackTop = (-position.y) > 1000
    }

  }
}